var class_num=location.search;
class_num=class_num.split('?')[1];
console.log(class_num);
$('header .title').append(class_num);
$("input[name='update_num']").attr('value',class_num);
if (islogin()) {
    $.post({
        url:'../../requests/teacher/select_class_name.php',
        data:{'class_num':class_num},
        async:false,
        success:function (data) {
            $("input[name='update_name']").attr('value',data);
        }
    });
    $('#btn_edit').click(function () {
        var update_num=$("input[name='update_num']").val();
        var update_name=$("input[name='update_name']").val();
        if (update_num!=""&&update_name!="") {
            $.post({
                url:'../../requests/teacher/edit_class.php',
                data:{'class_num':class_num,'update_class_num':update_num,'update_class_name':update_name},
                success:function (data) {
                    console.log(data);
                    if (data == "1") {
                        $$.alert('点击确定返回班级列表','修该成功',function () {
                            window.location.href='class.html';
                        });
                    }
                    else if (data=='exist1') {
                        $$.alert('已修改名称,点击确定返回班级列表','代码重复',function () {
                            window.location.href='class.html';
                        });
                    }
                    else $$.alert('修改失败');
                }
            });
        }
        else {
            $$.alert('代码和名称不能为空');
        }

    });
    $('#btn_del').click(function () {
        $$.confirm('删除班级将删除该班级所有学生','是否继续?',function () {
            $.post({
                url:'../../requests/teacher/delete_class.php',
                data:{'class_num':class_num},
                success:function (data) {
                    if (data=='no_stu') {
                        $$.alert('已删除班级,该班没有学生','删除成功',function () {
                            window.location.href='class.html';
                        });
                    }
                    else if (data == '1') {
                        $$.alert('已删除班级和学生','删除成功',function () {
                            window.location.href='class.html';
                        });
                    }
                    else $$.alert(data);
                }
            });
        });
    });
}
else window.location.href='../../index.html';